/**
 * 
 */
package jpb;

import java.util.List;

/**
 * Utility for simple common assertions.
 * 
 * @author Dariusz Kordonski
 */
public final class Assert {

    private Assert() {
        throw new AssertionError("Don't instantiate me");
    }

    /**
     * Assert that value <tt>value</tt> of the argument named <tt>name</tt> is not
     * <code>null</code>.
     * 
     * @param name
     *            name of the argument
     * @param value
     *            value of the argument
     * @param <T> type of the argument instance
     * @return the verified <tt>value</tt> (given assertion passed)
     */
    public static <T> T notNull(String name, T value) {
        if (value == null) {
            throw new NullPointerException(name);
        }
        return value;
    }

    /**
     * Assert that <tt>value</tt> is not an empty list.
     *
     * @param name name of the argument
     * @param value value of the argument
     * @param <T> component type of the argument
     * @return the verified <tt>value</tt> (given assertion passed)
     */
    public static <T> List<T> notEmpty(String name, List<T> value) {
        if (value.isEmpty()) {
            throw new IllegalArgumentException("<" + name + "> should not be empty");
        }
        return value;
    }


    /**
     * Assert that <tt>value</tt> is not an empty array.
     *
     * @param name name of the argument
     * @param value value of the argument
     * @param <T> component type of the argument
     * @return the verified <tt>value</tt> (given assertion passed)
     */
    public static <T> T[] notEmpty(String name, T[] value) {
        if (value.length == 0) {
            throw new IllegalArgumentException("<" + name + "> should not be empty");
        }
        return value;
    }
}
